package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IMemberReservationService;
import com.zzyl.nursing.vo.ReservationCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member/reservation")
@Api(value = "会员预约管理")
public class MemberReservationController extends BaseController {

    @Autowired
    private IMemberReservationService memberReservationService;
    @GetMapping("/cancelled-count")
    @ApiOperation(value = "获取已取消预约数量")
    public AjaxResult cancelledCount() {
        Long count = memberReservationService.cancelledCount();
        return AjaxResult.success(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation(value = "查询每个时间段剩余预约次数")
    public AjaxResult countByTime(Long time) {
        List<ReservationCountVo> count = memberReservationService.countByTime(time);
        return AjaxResult.success(count);
    }
    /**
     *  新增预约人
     */
    @PostMapping
    @ApiOperation(value = "新增预约人")
    public AjaxResult add(@RequestBody ReservationDto dto) {
        memberReservationService.add(dto);
        return AjaxResult.success();
    }
    /**
     *  分页查询
     */

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public AjaxResult pageSize(ReservationDto dto) {
        List<Reservation> list = memberReservationService.pageSize(dto);
        TableDataInfo tableDataInfo = getDataTable(list);
        return AjaxResult.success(tableDataInfo);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation(value = "取消项目订单")
    public AjaxResult cancel(@PathVariable Long id) {
        memberReservationService.cancel(id);
        return AjaxResult.success();
    }















}
